<template>
	<view class="container" :style="{'min-height':contentHeight}">
		<view class="t-box-line">
			<view class="t-box-line-box">
				<view class="t-box-line-left">
					<view class="t-box-line-left-inner">
						<text>{{nowDateY}}年{{nowDateM}}月</text>
						<view class="t-box-line-left-inner-time">
							<xp-picker mode="ym" ref="picker" @confirm="confirm" />
						</view>
					</view>
				</view>
				<view class="t-box-line-right">
					<view class="t-box-line-right-left">
						<text>收入￥</text><text>{{inAccount}}</text>
					</view>
					<view class="t-box-line-right-right">
						<text>支出￥</text><text>{{outAccount}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 流水列表 -->
		<view class="flow-list">
			<view v-for="(item,index) in flowList" :key="item.id">
				<view>
					<view>{{ item.remark}}</view>
					<view>{{ item.createTime }}</view>
				</view>
				<view>
					<view :class="item.amount > 0 ? 'add' : 'reduce'">
						{{ item.amount > 0 ? `+${item.amount/100}` : item.amount/100 }}
					</view>
					<!-- <view v-if="item.type==12 && item.userDraw"> -->
					<view style="position: relative;">
						<view :class="['tip']" v-if="showTips&&changeIndex==index"> 包含服务费{{item.userDraw.amountys/100}}元
						</view>
						<view @click="showTip(index,$event)" :data-index="index"
							:class="[(item.checkText=='提现审核中'&&'incon1')||(item.checkText=='提现成功'&&'incon')||('none')]">
							!</view>
						<text v-if="item.checkText=='提现审核中'"
							style="background: #DB1211;padding: 2rpx 10rpx;color: #fff;border-radius: 4rpx;font-size: 20rpx; margin-right: 10rpx;">
							{{item.checkText}} </text>
						<!--  -->
						<text v-if="item.checkText=='提现成功'"
							style="background: #A2A2A2;padding: 2rpx 10rpx;color: #fff;border-radius: 4rpx;font-size: 20rpx; margin-right: 10rpx;">
							{{item.checkText}} </text>
					</view>
					<view id="blackFontColor" v-if="item.type==13 && item.userDraw">
						<!-- <text>{{item.userDraw.remark.split('：')[1]}}</text> -->
						<view style="position: relative;margin-right: 80rpx;">提现审核未通过：
							<!-- <text style="color: #409EFF;"></text> -->
						</view>
						<view class="tips1" style="position: absolute;right:0;bottom:14%;z-index: 9;">
							<uni-tooltip :styleType4="1" :styleType="1" :styleType2="1" :styleType3="0"
								:content="item.userDraw.remark.split('：')[1]">
								<text style="color: #409EFF;">查看原因</text>
							</uni-tooltip>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 加载 -->
		<uni-load-more :status="hasFlag ? 'loading' : 'noMore'"></uni-load-more>
		<view v-if="isShowAmountFrozenInfo" class="AmountFrozenInfo-mask" @click="isShowAmountFrozenInfo=false">
			<view class="AmountFrozenInfo-content">
				<image @click="isShowAmountFrozenInfo=false" src="../../static/icon3/gb.png" mode="aspectFill"></image>
				<view class="AmountFrozenInfo-content-text-view">
					<text>冻结金额(元)</text>
					<text>{{amountFrozen/100}}</text>
				</view>
				<view class="jf-time">
					<view class="jf-time-title">
						<text>解禁押金</text>
						<text>{{amountFrozen/100}}</text>
					</view>
					<view class="jf-time-timeInfo">{{expireTime}} 解除冻结</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import unit from '../../libs/newUnit.js'
	import {
		getToExceedTheTime,
		getUserInfo
	} from '../../libs/unit.js'
	import moment from 'moment'
	moment.locale('zh-cn');
	export default {
		data() {
			return {
				contentHeight: "",
				hasFlag: true, // 是否还有更多数据要加载
				amount: 5000, //
				userInfo: {
					user: {},
					params: {}
				}, //当前用户信息
				flowList: [], //资金流水
				flowObj: { //(type 0 资金 50 诚信值)
					type: 0,
					findDate: '',
					pageNum: 0,
					pageSize: 10,
				},
				amountFrozen: 0,
				isShowAmountFrozenInfo: false,
				expireTime: '',
				isRecharge: false,
				nowDateY: moment(new Date().getTime()).format('YYYY'),
				nowDateM: moment(new Date().getTime()).format('MM'),
				inAccount: 0,
				outAccount: 0,
				showTips: false,
				changeIndex: -1
			}
		},
		methods: {
			showTip(e, l) {
				this.changeIndex = l.target.dataset.index
				this.showTips = !this.showTips
			},
			async getTwater() {
				let res = await this.$fetch(this.$api.my_flow_static, this.flowObj, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.inAccount = res.data.inAccount
				this.outAccount = res.data.outAccount
			},
			async confirm(e) {
				this.nowDateY = e.value.split("-")[0]
				this.nowDateM = e.value.split("-")[1]
				this.flowObj.findDate = e.value
				this.flowObj.pageNum = 0
				this.flowList = []
				this.hasFlag = true
				this.my_flow()
				this.getTwater()
			},
			// 获取资金流水
			async my_flow() {
				if (!this.hasFlag) return // 说明已经没有更多啦

				++this.flowObj.pageNum
				let res = await this.$fetch(this.$api.my_flow, this.flowObj, 'POST')
				// console.log('获取资金流水', res)
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				uni.stopPullDownRefresh()
				// 拼接
				this.flowList = [...this.flowList, ...res.rows]
				this.hasFlag = this.flowList.length < res.total
			},
			// 打开内页面
			handleOpenPage(page) {
				if (page == 0) {
					uni.navigateTo({
						url: '/pages/prepaid/prepaid'
					})
					this.isRecharge = !this.isRecharge
					// uni.showToast({
					// 	title: '暂不开放',
					// 	icon: 'none'
					// })
				} else {
					if (this.amountFrozen > 0) {
						uni.navigateTo({
							url: '/pages/cash-out/cash-out?amountFrozen=' + this.amountFrozen
						})
					} else {
						uni.navigateTo({
							url: '/pages/cash-out/cash-out'
						})
					}
				}
			},
			// 刷新
			refresh() {
				this.flowList = []
				this.hasFlag = true
				this.flowObj.pageNum = 0
				this.flowObj.pageSize = 10
				this.my_flow()
				this.getTwater()
				this.getUserInfo()
				console.log(this.userInfo.amount)
			},
			async getUserInfo() {
				let res = await this.$fetch(this.$api.get_current_user, {}, 'GET')
				if (res.code) return;
				this.userInfo = res.data
			},
			getAmountFrozen() {
				if (uni.getStorageSync('jf_expireTime')) {
					let jf_expireTime = getToExceedTheTime(uni.getStorageSync('jf_expireTime'))
					if (jf_expireTime < 0) {
						if (uni.getStorageSync('yajinItem')) {
							if (uni.getStorageSync('yajinItem').status == 1) {
								this.amountFrozen = uni.getStorageSync('yajinItem').deposit
								this.expireTime = uni.getStorageSync('yajinItem').expireTime
								let expireT = getToExceedTheTime(this.expireTime)
								if (expireT >= 0) {
									try {
										uni.removeStorageSync('jf_expireTime')
										uni.removeStorageSync('yajinItem')
									} catch (e) {
										// error
									}
									this.amountFrozen = 0
								}
							}
						} else {
							unit.Closure_margin().then(v => {
								if (v.data != '0') {
									if (v.data.status == 1) {
										this.amountFrozen = v.data.deposit
										this.expireTime = v.data.expireTime
									}
								}
							})
						}
					} else {
						try {
							uni.removeStorageSync('jf_expireTime')
						} catch (e) {
							// error
						}
					}
				}
			},
		},
		onShow() {
			this.getAmountFrozen()
		},
		onLoad() {
			this.contentHeight = uni.getWindowInfo().windowHeight + "px"
			this.flowObj.findDate = this.nowDateY + '-' + this.nowDateM
			this.refresh()
		},
		onReachBottom() {
			this.my_flow()
		},
		onPullDownRefresh() {
			//监听用户下拉动作，一般用于下拉刷新
			this.refresh()
		}
	}
</script>
<style lang="less" scoped>
	.container {
		background-color: #fff;

		.t-box-line {
			width: 100%;
			height: 152rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background-color: #F1F1F5;
			padding: 6rpx 0;
			box-sizing: border-box;

			.t-box-line-box {
				width: 92%;

				.t-box-line-left {
					height: 60rpx;
					font-size: 40rpx;
					font-weight: bold;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.t-box-line-left-inner {
						font-size: 28rpx;
						position: relative;

						.t-box-line-left-inner-time {
							position: absolute;
							right: -25%;
							bottom: 6rpx;
							display: flex;
							justify-content: center;
							align-items: center;
						}
					}
				}

				.t-box-line-right {
					height: 60rpx;
					color: #7F7F7F;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					margin-right: 10rpx;

					.t-box-line-right-left {
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 24rpx;

						text:last-child {
							font-size: 28rpx;
						}
					}

					.t-box-line-right-right {
						display: flex;
						justify-content: center;
						align-items: center;
						margin-left: 60rpx;
						font-size: 24rpx;

						text:last-child {
							font-size: 28rpx;
						}
					}
				}
			}
		}

		&>.flow-list {
			background-color: #FFFFFF;
			min-height: calc(100vh - 420rpx);

			&>view {
				height: 148rpx;
				width: 690rpx;
				position: relative;
				padding-left: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				padding: 28rpx 0rpx 24rpx 30rpx;

				&>view {
					height: 96rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;

					&>view:nth-child(1) {
						font-size: 32rpx;
						color: #1A1A1A;
						margin-bottom: 10rpx;
					}

					&>view:last-child {
						font-size: 28rpx;
						color: #7F7F7F;
					}
				}

				&>view:last-child {
					align-items: flex-end;

					&>.add {
						font-weight: bold;
						font-size: 17px;
						color: #4E9800;
					}

					&>.reduce {
						font-weight: bold;
						font-size: 17px;
						color: #C9281C;
					}
				}

				&::before {
					content: "";
					position: absolute;
					top: 144rpx;
					width: 690rpx;
					height: 2rpx;
					background: #F2F2F2;
					border-radius: 1px;
				}
			}
		}
	}

	.incon {
		display: inline-block;
		background: rgba(255, 46, 0);
		width: 32rpx;
		height: 32rpx;
		color: #fff;
		border-radius: 50%;
		min-width: 32rpx;
		text-align: center;
		line-height: 32rpx;
		margin-right: 10rpx;
	}

	.incon1 {
		display: inline-block;
		background: rgba(162, 162, 162);
		width: 32rpx;
		height: 32rpx;
		color: #fff;
		border-radius: 50%;
		min-width: 32rpx;
		text-align: center;
		line-height: 32rpx;
		margin-right: 10rpx;
	}

	.none {
		display: none;
	}

	.tip {
		font-size: 20rpx;
		background: #a3a3a3;
		color: #fff;
		border-radius: 10rpx;
		padding: 7rpx 20rpx;
		position: absolute;
		right: -30rpx;
		bottom: -60rpx;
		z-index: 999;
		min-width: 250rpx;
	}
</style>